package itheima.moc.myreflect5;

import java.lang.reflect.Method;

public class ReflectDemo {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
//        method1();
//        method2();
//        method3();
        Class clazz = Class.forName("itheima.moc.myreflect5.Student");
        Method declaredMethod = clazz.getDeclaredMethod("show");
        System.out.println(declaredMethod);

    }

    private static void method3() throws ClassNotFoundException, NoSuchMethodException {
        Class clazz = Class.forName("itheima.moc.myreflect5.Student");
        Method method = clazz.getMethod("fun1");
        System.out.println(method);

        Method method2 = clazz.getMethod("fun2",String.class);
        System.out.println(method2);

        Method method3 = clazz.getMethod("fun4",String.class);
        System.out.println(method3);
    }

    private static void method2() throws ClassNotFoundException {
        //所有方法
        Class clazz = Class.forName("itheima.moc.myreflect5.Student");
        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
        }
    }

    private static void method1() throws ClassNotFoundException {
        //所有公共方法
        Class clazz = Class.forName("itheima.moc.myreflect5.Student");
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
    }
}
